﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using HuanGis;

using DotSpatial.Map;

namespace Map6Exe
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();

           
        }

        FLayerManager m_M;
        TreeViewHelper m_tvHelper;

        private void frmMain_Load(object sender, EventArgs e)
        {

            m_M = new FLayerManager(map1);


            m_M.NewProj(@"c:\");


            m_M.MfSystem.ShapeAdded += new ShapeHandler(MfSystem_ShapeAdded);
            
                       


            m_tvHelper = new TreeViewHelper(m_M ,this.treeView1 ,this.propertyGrid1 );

                        
            FEPolygonLayer PloygonRectanle = new FEPolygonLayer("Rectanle");

            m_M.AddLayer(PloygonRectanle);

            FEPolygonLayer PolygonCircle = new FEPolygonLayer("Circle");
            m_M.AddLayer(PolygonCircle);

            FEPolygonLayer PolygonSquare = new FEPolygonLayer("Square");
            m_M.AddLayer(PolygonSquare);

            FEPointLayer PointLayer = new FEPointLayer("Point");
            m_M.AddLayer(PointLayer);

            FELineLayer LineLayer = new FELineLayer("Line");
            m_M.AddLayer(LineLayer);

            FEPolygonLayer PolygonLayer = new FEPolygonLayer("Polygon");
            m_M.AddLayer(PolygonLayer);


            FDGridLayer gridLayer = new FDGridLayer("grid");
            gridLayer.descString = "网格";

            m_M.AddLayer(gridLayer );

            //=============================================================
            FDContourLayer contourlayer = new FDContourLayer("contour");

            contourlayer.descString = "等值线";
            m_M.AddLayer(contourlayer);

            //下面的函数不允许外部调用
            //contourlayer.Redraw();

            //=========================================================


            map1.ZoomToMaxExtent();

        }


        void MfSystem_ShapeAdded(FShape shp)
        {

            this.m_M.LayerSystem.AddShape(shp);

            
        }

      
          

   

        private void point_Click(object sender, EventArgs e)
        {
            this.m_M.MfSystem .UseFunction ("Point", SFunctionEnum.POINT);
            sf = "Point";
        }

        private void line_Click(object sender, EventArgs e)
        {
            this.m_M.MfSystem.UseFunction("Line", SFunctionEnum.lINE);
        }

        private void poly_Click(object sender, EventArgs e)
        {
            this.m_M.MfSystem.UseFunction("Polygon", SFunctionEnum.POLYGON);
        }

        private void circle_Click(object sender, EventArgs e)
        {
            this.m_M.MfSystem.UseFunction("Circle", SFunctionEnum.CIRCLE);
            sf = "Circle";
        }

        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            this.m_M.MfSystem.UseFunction("Rectanle", SFunctionEnum.RECTANGLE);
            sf = "Rectanle";
        }

        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            this.m_M.MfSystem.UseFunction("Square", SFunctionEnum.SQUARE);
            sf = "Square";
        }

        private string sf;

        private void toolStripButton1_Click(object sender, EventArgs e)
        {

            this.m_M.CurrentMap.FunctionMode = FunctionModes.Select;
            //this.m_M.SetMF(sf, SFunctionEnum.SELECT);
            

        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            this.m_M.MfSystem.UseFunction("ALL", SFunctionEnum.MOVE);
        }

        private void 全屏ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.map1.ZoomToMaxExtent();
        }

        private void 放在ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            map1.FunctionMode = FunctionModes.ZoomIn;
        }

        private void 打开SHPToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog fld = new OpenFileDialog();
            //fld.ShowDialog();
            DotSpatial.Data.FeatureSet fs = new DotSpatial.Data.FeatureSet();
            if (fld.ShowDialog() == DialogResult.OK)
            {
                fs.Open(fld.FileName);
                map1.Layers.Add(fs);
            }
        }

        private void 平移ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            map1.FunctionMode = FunctionModes.Pan;
        }
    }
}
